#include  <fftw3.h>
#include	<stdio.h>
#include	<stdlib.h>
#include	<math.h>

int main( int argc, char** argv )
{
	/* Initialize */
	int N = 16;
	fftw_plan pr2hc, phc2r;
	double *in;
	double *out;
	int i, j, k;
	double PI = 4.0 * atan(1.0);

	/* Setup */
	in = (double*)malloc(sizeof(double) * N );
	out = (double*) malloc(sizeof(double) * N );

	for( i = 0; i < N; i++ )
	{
		in[i] = sin( 2.0 * PI * (double)(i) / (double)(N) );
	}

	/* Compute */	

	pr2hc = fftw_plan_r2r_1d( N, in, out, FFTW_R2HC, FFTW_ESTIMATE );
	fftw_execute(pr2hc);
	phc2r = fftw_plan_r2r_1d( N, out, in, FFTW_HC2R, FFTW_ESTIMATE );
	fftw_execute(phc2r);
	
	for ( i = 0; i < N ; i++ )
	{
		printf("%5.2f, ", in[i] );
	}

	/* Free space */
	fftw_destroy_plan(pr2hc);
	fftw_destroy_plan(phc2r);
	free(in);
	free(out);
	return EXIT_SUCCESS;
}

